package logic

import (
	"context"
	"errors"
	"github.com/zeromicro/go-zero/core/logx"
	"gitignore/gitignorerpc/gitignorerpc"
	"gitignore/gitignorerpc/internal/svc"
	"gitignore/models/mysql"
)

type CollectionLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectionLogic {
	return &CollectionLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CollectionLogic) Collection(in *gitignorerpc.CollectionRequest) (*gitignorerpc.CollectionResponse, error) {
	// todo: add your logic here and delete this line
	collect := mysql.Collection{
		//Model:          gorm.Model{},
		User_id:        int(in.UserId),
		Video_id:       int(in.VideoId),
		Collect_time:   in.CollectTime,
		Collect_status: in.CollectStatus,
	}

	err := collect.FindCollectByAdd(mysql.DB)
	if err != nil {
		return nil, errors.New("收藏失败")
	}

	return &gitignorerpc.CollectionResponse{
		CollectId: int64(collect.ID),
	}, nil
}
